#include <SDL/SDL.h>
#include <stdio.h>

int main ()
{
  SDL_Surface *screen;
  SDL_Event event;

  // Init SDL's video system.
  if (SDL_Init(SDL_INIT_VIDEO) != 0) {
    printf("Unable to initialize SDL: %s\n", SDL_GetError());
    return 1;
  }
  
  // Call SDL_Quite when the program exists.
  atexit(SDL_Quit);

  // Set the video mode.
  screen = SDL_SetVideoMode(640, 480, 16, 0);
  if (screen == NULL) {
    printf("Unable to set video mode: %s\n", SDL_GetError());
    return 1;
  }

  // Start the event loop.
  while (SDL_WaitEvent(&event) != 0) {
    
    // Check the event type.
    switch (event.type) {

      // Mouse activity.
    case SDL_MOUSEMOTION:

      printf("Mouse motion. ");

      // Current position.
      printf("Current position is [%i, %i]. ", 
	     event.motion.x, event.motion.y);
      // Relative position.
      printf("That's a [%i, %i] change. ", 
	     event.motion.xrel, event.motion.yrel);

      break;

      // Mouse button pressed.
    case SDL_MOUSEBUTTONDOWN:
      
      printf("Mouse button pressed. ");

      printf("Button %i at [%i, %i]\n", 
	     event.button.button,
	     event.button.x, event.button.y);

      break;

      // Close window.
    case SDL_QUIT:
      
      printf("Quit event. Bye.\n");
      exit(0);
    }

  }

  return 0;
}
